package com.hafu.dao;

import com.hafu.model.Inventory;
import com.hafu.util.DbUtil;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 * @Author:xiaohai 2072158919@qq.com 海航源
 * @Date: 2024/11/1  下午8:54
 * @Version 1.0
 * @description
 */
public class InventoryDao {
    public ArrayList<Inventory> getinventoryList() throws SQLException {
        Connection connection = DbUtil.getConnection();
        String sql = "select * from kucun";
        java.sql.PreparedStatement preparedStatement = connection.prepareStatement(sql);
        java.sql.ResultSet resultSet = preparedStatement.executeQuery();
        ArrayList<Inventory> inventoryList = new ArrayList<>();
        while (resultSet.next()) {
            int id = resultSet.getInt("id");
            String name = resultSet.getString("spname");
            int num = resultSet.getInt("num");
            Inventory inventory = new Inventory(id, name, num);
            inventoryList.add(inventory);

        }
        return inventoryList;
    }
}
